package com.groupbuying.customerconsumer.mq;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 支付中心消息生产mq配置
 *
 * @Author Vincentxin
 * @Date 2019-05-10
 */
@Configuration
public class CustomerMQProducer {

    public static final Logger LOGGER = LoggerFactory.getLogger(CustomerMQProducer.class);

    public CustomerMQProducer() {
    }

    @Bean
    public Producer getCustomerMQProducer() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, CustomerMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, CustomerMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, CustomerMQConfig.NAMESRV_ADDR);
        Producer producer = ONSFactory.createProducer(properties);
        try {
            producer.start();
            LOGGER.info("用户中心-消费模块生产者  groupId:{}", CustomerMQConfig.GROUP_ID);
        } catch (Exception var4) {
            LOGGER.error("用户中心-消费模块生产者启动失败  groupId:{}，错误原因:{}", CustomerMQConfig.GROUP_ID, var4.getMessage());
        }

        return producer;
    }
}
